package com.tuanzi.loan.web.bean.family;

import com.google.common.collect.Lists;
import com.tuanzi.loan.business.service.family.ClassificationService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.vo.request.family.ClassificationInfoSearchRequest;
import com.tuanzi.loan.vo.response.family.ClassificationInfoListResponse;
import com.tuanzi.loan.web.configuration.JSFListingSessionBean;
import com.tuanzi.loan.web.lazy.family.ClassificationDataModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.faces.bean.ViewScoped;
import java.util.List;

import static com.tuanzi.loan.business.constants.DictionaryCode.ONLINE_OFFLINE_STATUS;

@Data
@Debug
@Component
@ViewScoped
@EqualsAndHashCode(callSuper = true)
public class ClassificationListBean extends JSFListingSessionBean<ClassificationInfoSearchRequest,ClassificationInfoListResponse> {

    private static final long serialVersionUID = -4853561191312722987L;
    @Autowired
    private ClassificationService classificationService;


    public void delete(String id){
        classificationService.deleteClassifById(Long.parseLong(id));
        onReset();
    }

    public String onAdd(){
        return redirect("/views/family/member/classification_add.xhtml");
    }

    public String onEdit(String id) {
        return redirect("/views/family/member/classification_add.xhtml?id=" + id);
    }

    @Override
    protected String page() {
        return "/views/family/member/classification_info.xhtml";
    }

    @Override
    protected void initLazyDataModel() {
        $ = new ClassificationInfoSearchRequest();
        lazyDataModel = new ClassificationDataModel($, session, classificationService);
    }

    public void onReset() {
        initLazyDataModel();
    }

    @Override
    protected List<String> getDictionaryCodes() {
        return Lists.newArrayList(ONLINE_OFFLINE_STATUS);
    }

}
